<html>
<%@ include file="../../common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		
		<title><fmt:message key="format.message.system" /></title>
	</head>
  <body>
  <script type="text/javascript">
  Ext.namespace('azure', 'azure.common');
  azure.common.betSetting = function() {
  	/* ----------------------- private属性 ----------------------- */
  	var store_betSetting;
  	var grid_betSetting;
  	var rec_betSetting;
  	var cm_betSetting;
  	var tree_betSetting;
  	var form_betSetting, win_betSetting,updateBetSettingForm;
  	var f_enable;
  	/* ----------------------- private方法 ----------------------- */
  	function createCM() {
  		cm_betSetting = new Ext.grid.ColumnModel([
  			{header:'<fmt:message key="format.betSetting.cellName" />',width:50,dataIndex : 'cellName'},
  			{header:'<fmt:message key="format.betSetting.rate" />',width:100,dataIndex : 'rate'},
  			{header:'<fmt:message key="format.betSetting.maxBet" />',width:80,dataIndex : 'maxBet'},
  			{header:'<fmt:message key="format.content.Operation" />',width:100,dataIndex : 'maxBet',renderer : function(val, p, record) {
				return '<b><a href="#" onclick="javascript:editbetSetting();"}><fmt:message key="format.content.update" /></a>';
			}}
  		]);
  	}
  	function createStore() {
  		store_betSetting = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : 'Agent_findBetSetting.action'
			}),
			reader : new Ext.data.JsonReader({
				root : 'pager.data',
				totalProperty : 'pager.totalSize'
			}, [{
				name : 'cellid',
				mapping : 'cellid'
			}, {
			name : 'cellName',
			mapping : 'cellName'
		}, {
			name : 'rate',
			mapping : 'rate'
		}, {
			name : 'minBet',
			mapping : 'minBet'
		}, {
			name : 'maxBet',
			mapping : 'maxBet'
		}, {
			name : 'gamePlayId',
			mapping : 'gamePlayId'
		}, {
			name : 'agentid',
			mapping : 'agentid'
		}])
		});

  	}
  	function createGrid() {
  		createCM();
  		createStore();
  		
  		grid_betSetting = new Ext.grid.GridPanel({
  			store: store_betSetting,
  			cm: cm_betSetting,
  			width:800,
  			height:455,
  			renderTo: Ext.getBody(),
  			bbar: new Ext.PagingToolbar({
  				store: store_betSetting,
  				displayInfo: true,
  				pageSize: 5,
				displayMsg : '<fmt:message key="format.content.pager" />',
				emptyMsg : '<fmt:message key="format.content.emptyMsg" />'
  			})
  		});
  	}
  	function createTree() {
  		var root = new Ext.tree.AsyncTreeNode('<fmt:message key="format.history.game" />');
  		tree_betSetting = new Ext.tree.TreePanel({
  			width:200,
  			autoHeight : true,
  			root: root,
  			loader: new Ext.tree.TreeLoader({dataUrl:'Agents_createTreeJson.action'})
  		});
  		tree_betSetting.on('click',function(node){
  			grid_betSetting.show(Ext.getBody());

  			store_betSetting.load({params:{start:0,limit:15,'gamePlayId':node.attributes.pid}});
     		});
  	}
  	function createForm() {
		updateBetSettingForm = new Ext.form.FormPanel({
			labelWidth : 65,
			frame : true,
			url:'Agent_updateBetSetting.action',
			labelSeparator : ':',
			labelAlign : 'left',
			defaultType : 'textfield',
			items : [
			new Ext.form.Hidden({
				id:'cellid',
				name : 'bet.bettingCell.id'
			}),new Ext.form.Hidden({
				id:'agentid',
				name : 'bet.agent.uno'
			}),new Ext.form.TextField({
				id:'cellName',
				fieldLabel : '<fmt:message key="format.betSetting.cellName"/>',
				width : 220
			}),new Ext.form.TextField({
				id:'rate',
				fieldLabel : '<fmt:message key="format.betSetting.rate"/>',
				width : 220
			}),new Ext.form.TextField({
				id:'minBet',
				fieldLabel : '<fmt:message key="format.betSetting.minBet"/>',
				name : 'bet.minBet',
				width : 220
			}),new Ext.form.TextField({
				id:'maxBet',
				fieldLabel : '<fmt:message key="format.betSetting.maxBet"/>',
				width : 220,
				name : 'bet.maxBet'
			})]
		});
	}
  	// 创建主界面
  	function createUI() {
  		createGrid();
  		createTree();
  		createForm();
  		grid_betSetting.hide();
  		new Ext.Panel({
  			height:535,
  			renderTo: 'betSettingDiv',
  			layout:'border',
  			items: [
  				{region: 'west', width: 200, items: tree_betSetting},
  				{region: 'center', items: grid_betSetting}
  			]
  		});
  	}

  	editbetSetting=function () {
  		win_betSetting = new Ext.Window({
			width : 320,
			height : 300,
			closable : false,
			layout : 'fit',
			items : updateBetSettingForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.message.confirm"/>',
				handler : updatebetSetting,
				formBind : true
			}, {
				text : '<fmt:message key="format.message.cancel"/>',
				handler : function() {
					win_betSetting.hide();
				}
			}]
		});
		var rec = grid_betSetting.getSelections()[0];
		if (rec != null) {
			win_betSetting.title = '<fmt:message key="format.content.update"/>';
			win_betSetting.show(Ext.getBody());
			updateBetSettingForm.getForm().loadRecord(rec);
		} else {
			Ext.MessageBox.alert('<fmt:message key="format.content.Warning"/>',
				'<fmt:message key="format.content.aterror"/>');
		}
	}

	function updatebetSetting(btn){
		var rec = grid_betSetting.getSelections()[0];
		if(updateBetSettingForm.getForm().isValid()){
			btn.disable();
			updateBetSettingForm.getForm().submit({
				method : 'POST',
				waitMsg : '<fmt:message key="format.message.saving"/>',
				successProperty : false,
				success : function() {
					Ext.Msg.alert('<fmt:message key="format.message.success"/>', 
					'<fmt:message key="format.message.update.success"/>',function() {
						btn.enable();
						store_betSetting.reload();
					});
				},
				failure : function() {
					Ext.Msg.alert('<fmt:message key="format.message.failure"/>', 
					'<fmt:message key="format.message.update.failure"/>');
					btn.enable();
				}
			});
			}
	}
  	/* ----------------------- public方法 ----------------------- */
  	return {
  		//初始化
  		init : function() {
  			createUI();
  		}
  	};
  }();
  Ext.EventManager.onDocumentReady(azure.common.betSetting.init, azure.common.betSetting, true);
  </script>
  	<div id="betSettingDiv"></div>
  </body>
</html>
